package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendExtraJsonAddDTO;
import org.jsola.hr.dto.AttendExtraJsonUpdateDTO;
import org.jsola.hr.entity.AttendExtraJsonDO;
import org.jsola.hr.query.AttendExtraJsonQuery;
import org.jsola.hr.service.IAttendExtraJsonService;
import org.jsola.hr.vo.AttendExtraJsonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendExtraJsonTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendExtraJsonService attendExtraJsonService;

    /**
     * 生成add测试数据
     * @return AttendExtraJsonAddDTO
     */
    public AttendExtraJsonAddDTO getAttendExtraJsonAddDTO(){
        AttendExtraJsonAddDTO attendExtraJsonAddDTO = new AttendExtraJsonAddDTO();
        attendExtraJsonAddDTO.setAttendPalnId(getRandomValue("varchar",32));
        attendExtraJsonAddDTO.setExtraType(SafeKit.getInteger(getRandomValue("int",0)));
        attendExtraJsonAddDTO.setJsonData(getRandomValue("text",65535));
        attendExtraJsonAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendExtraJsonAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendExtraJsonUpdateDTO
     */
    public AttendExtraJsonUpdateDTO getAttendExtraJsonUpdateDTO(AttendExtraJsonVO attendExtraJsonVO){
        return attendExtraJsonService.selectDOById(attendExtraJsonVO.getId(), SITE_ID).to(AttendExtraJsonUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendExtraJsonQuery
     */
    public AttendExtraJsonQuery getAttendExtraJsonQuery() {
        AttendExtraJsonQuery attendExtraJsonQuery = new AttendExtraJsonQuery();
        List<AttendExtraJsonDO> attendExtraJsonDOList = attendExtraJsonService.list(new AttendExtraJsonDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendExtraJsonDOList)) {
            AttendExtraJsonDO attendExtraJsonDO = attendExtraJsonDOList.get(0);
            attendExtraJsonQuery = attendExtraJsonDO.to(AttendExtraJsonQuery.class);
            if (attendExtraJsonDO.getGmtCreate() != null) {
                attendExtraJsonQuery.setGmtCreateStart(DateKit.getBeforeDay(attendExtraJsonDO.getGmtCreate(),-1));
                attendExtraJsonQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendExtraJsonDO.getGmtCreate(),1));
            }
            if (attendExtraJsonDO.getGmtModified() != null) {
                attendExtraJsonQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendExtraJsonDO.getGmtModified(),-1));
                attendExtraJsonQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendExtraJsonDO.getGmtModified(),1));
            }
        }
        return attendExtraJsonQuery;
    }

    /**
     * 保存示例
     * @return AttendExtraJsonVO
     */
    public AttendExtraJsonVO saveAttendExtraJsonExample(){
        AttendExtraJsonAddDTO addDTO = this.getAttendExtraJsonAddDTO();
        AttendExtraJsonVO attendExtraJsonVO = attendExtraJsonService.save(addDTO,buildTokenUser());
        return attendExtraJsonVO;
    }


}

